package Operation;

import Book.BookList;

import java.util.Scanner;

public class BorrowedOperation implements ioperation{
    public void work(BookList bookList) {
        System.out.println("借阅图书！");

        //输入借阅的书的名字
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要借的书的名字");
        String name = scanner.nextLine();

        //遍历书架来判断是否有相同书
        for (int i = 0; i < bookList.getUsedSize(); i++){
            //判断是否有这本书
            if(name.equals(bookList.getBooks(i).getName())){
                if(bookList.getBooks(i).getisIfBorrowed() == false){
                    //未被借阅，则成功借阅，直接退出，并且借阅状态为true
                    bookList.getBooks(i).setIfBorrowed(true);
                    System.out.println("您已成功借阅书籍《" + name + "》");
                    return;
                }else {
                    //存在该书但是被借出
                    System.out.println("该书已被借阅！");
                }
            }
        }

        System.out.println("很抱歉！未找到《"+ name + "》");
    }
}
